package client.comm.baoding.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.comm.commlib.network.data.JsonResult
import client.comm.commlib.network.data.Ret
import client.comm.baoding.api.bean.GoodsDetail
import client.comm.baoding.ui.viewmodel.MiddleVm

class GoodsOrderDetailModel(app: Application) : MiddleVm(app) {


    val goodsDetail = MutableLiveData<JsonResult<GoodsDetail>>()

    val isShowingDialog = MutableLiveData<Boolean>(false)
    val isShowing = MutableLiveData<Boolean>(false)
    val buyRet = MutableLiveData<JsonResult<Ret>>()
    val cancleCall = MutableLiveData<JsonResult<Ret>>()
    val qrshCall = MutableLiveData<JsonResult<Ret>>()
    val isShowSign = MutableLiveData<Boolean>(false)

    fun qrshCall(id: String) {
        isShowing.value = true
        hold({
            server.confirm_order(id)
        }, success = {
            qrshCall.value = it
        }, complete = {
            isShowing.value = false
        })
    }

    fun cancle(id: String) {
        isShowing.value = true
        hold({
            server.del_buy_order(id)
        }, success = {
            cancleCall.value = it
        }, complete = {
            isShowing.value = false
        })
    }

    fun holdCall(id: String, token: String?) {
        hold({
            server.goods_detail("${id}", token)
        }, {
            isShowing.value = true
        }, success = {
            goodsDetail.value = it
        }, complete = {
            isShowing.value = false
        })
    }

}